package com.bsoft.recycleviewtest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import static com.bsoft.recycleviewtest.DividerItemDecoration.VERTICAL_LIST;

public class MainActivity extends AppCompatActivity {

    private RecyclerView ryc_view;
    private TestAdapter adapter;
    private List<String> mDatas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initData();
        adapter = new TestAdapter(this, mDatas);
        ryc_view = (RecyclerView) findViewById(R.id.ryc_view);

        ryc_view.setLayoutManager(new LinearLayoutManager(this));
//        ryc_view.setLayoutManager(new GridLayoutManager(this, 4));
        ryc_view.setAdapter(adapter);
        ryc_view.addItemDecoration(new DividerItemDecoration(this,VERTICAL_LIST));
//        ryc_view.addItemDecoration(new DividerGridItemDecoration(this));

        adapter.setOnItemClickLitener(new TestAdapter.OnItemClickLitener() {

            @Override
            public void onItemClick(View view, int position) {
                Toast.makeText(MainActivity.this, position + " click",
                        Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onItemLongClick(View view, int position) {
                Toast.makeText(MainActivity.this, position + " long click",
                        Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initData() {

        mDatas = new ArrayList<String>();
        for (int i = 'A'; i < 'z'; i++) {
            mDatas.add("" + (char) i);
        }

    }
}
